class Solution:
    def summaryRanges(self, nums: List[int]) -> List[str]:
        n = len(nums)
        res = []
        j = 0
        for i in range(n):
            if i == n - 1 or nums[i + 1] - nums[i] != 1:
                sb = [str(nums[j])]
                if j != i:
                    sb.append("->")
                    sb.append(str(nums[i]))
                res.append("".join(sb))
                j = i + 1
        return res